package com.example.system.controller.exam;


import cn.hutool.core.util.StrUtil;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.exam.dto.ExamAddDTO;
import com.example.system.domain.exam.dto.ExamEditDTO;
import com.example.system.domain.exam.dto.ExamQueryDTO;
import com.example.system.domain.exam.dto.ExamQuestAddDTO;
import com.example.system.domain.exam.vo.ExamDetailVO;
import com.example.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO){
        String examId = examService.add(examAddDTO);
        if (StrUtil.isEmpty(examId)) {
            return R.fail();
        }
        return R.ok(examId);
    }

    @PostMapping("/question/add")
    public R<Void> addQuestion(@RequestBody ExamQuestAddDTO examQuestAddDTO){
        return toR(examService.addQuestion(examQuestAddDTO));
    }

    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId){
        return R.ok(examService.getExamDetail(examId));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toR(examService.edit(examEditDTO));
    }

    @DeleteMapping("/question/delete")
    public R<Void> delete(Long examId, Long questionId){
        return toR(examService.deleteQuestion(examId,questionId));
    }

    @DeleteMapping("/delete")
    public R<Void> delete(Long examId){
        return toR(examService.detele(examId));
    }

    @PutMapping("/publish")
    public R<Void> publish(Long examId){
        return toR(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId){
        return toR(examService.cancelPublish(examId));
    }
}
